package com.openarena.other.suggestions;

import com.openarena.logic.utils.FacesUtil;
import com.openarena.statistics.GameCTFStatistics;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class SuggestionForm {

    private static final Logger logger = Logger.getLogger(SuggestionForm.class.getCanonicalName());
    private String text;
    private String title;

    public SuggestionForm() {
    }

    public String getText() {
        return text;
    }

    public String getTitle() {
        return title;
    }

    public void setText(String text) {
        this.text = text;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void submit() {
        Suggestion suggestion = new Suggestion();
        suggestion.setText(text);
        suggestion.setTitle(title);
        suggestion.setIp(FacesUtil.getRemoteAddress());

        try {
            suggestion.saveToDisk();
            text = "";
            title = "";
            FacesUtil.addSuccessMessage("Comentario salvado. ","Su comentario es importante. No sera borrado en cuanto me pinte.");
        } catch (IOException ex) {
            logger.log(Level.SEVERE, null, ex);
            FacesUtil.addErrorMessage("Error al salvar su comentario. ","Por favor utilice esta misma herramienta"
                    + " para comunicarnos el error que encontro al usar esta herramienta, Gracias.");
        }
    }
}
